﻿using FairyGUI;
/// <summary>
/// 出牌指示
/// </summary>
public class UIGamePlayCardIndicator {
	GComponent _uiComp;
	GTextField _cutdownText;
	GTextField _remainCardsNum;
	Controller _idxCtrl;

	int _timeSec;
	bool _cutingDown = false;

	public UIGamePlayCardIndicator(GComponent uiComp)
    {
		_uiComp = uiComp;

		_cutdownText = _uiComp.GetChild ("倒计时").asTextField;
		_remainCardsNum = _uiComp.GetChild ("剩余牌").asTextField;
		_idxCtrl = _uiComp.GetController ("出牌控制");
    }

	public bool visible {
		get {
			return _uiComp.visible;
		}

		set {
			_uiComp.visible = _uiComp.enabled = value;

			if (value == false) {
				_timeSec = 0;
			}
		}
	}

	public void SetPlayCardIndex(int index) {
		_idxCtrl.selectedIndex = index;
		DebugInfo.Log ("UIGamePlayCardIndicator.SetPlayCardIndex: " + index);

		_timeSec = 9;
		_cutdownText.text = _timeSec + "";

		if (!_cutingDown) {
			Cutdown ();
		}
	}

	public void SetRemainCardNum(int num) {
		_remainCardsNum.text = "[color=#00CC00]剩余[/color][color=#CCFF00][size=16]"
			+ num 
			+ "[/size][/color][color=#00CC00]张[/color]";
	}

	void Cutdown() {
		_cutingDown = true;
		_cutdownText.text = _timeSec + "";
		if (_timeSec > 0) {
			TimerController.inst.CallAfter (1.0f, reqArgs => {
				_timeSec -= 1;
				Cutdown ();
			});
		} else {
			_cutingDown = false;
		}
	}
}
